import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GTextArea } from "../../../../com/mui/controls/GTextArea";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Cache } from "../../cache/Cache";
import { ItemsUtil } from "../shortcuts/item/ItemsUtil";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ItemData } from "../../resource/info/ItemData";
import { QuickBuyWindow } from "../common/QuickBuyWindow";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { MsgManager } from "../../manager/MsgManager";
import { SFireworkEventRecord } from "../../../../Message/Game/SFireworkEventRecord";
import { SFireworkEvent } from "../../../../Message/Game/SFireworkEvent";
import { EFireworkEventType } from "../../../../Message/Game/EFireworkEventType";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { ColorConfig } from "../../resource/ColorConfig";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class FireworkEventRecordsWindow
    
    export  class FireworkEventRecordsWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(328, 342);
            titleHeight = 26;
            title = Language.getString(43203);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            ObjCreate.createBg(18, 38, 292, 292, this);
            this._recordsTextArea = new GTextArea();
            ObjCreate.setObjAttri(this._recordsTextArea, 23, 43, 282, 200, this);
            this._recordsTextArea.editable = false;
            this._recordsTextArea.styleName = "GTextArea";
            this._recordsTextArea.textField.filters = [FilterConst.glowFilter];
            this._recordsTextArea.wordWrap = true;
            ObjCreate.createBg(25, 240, 280, 2, this, "SplitLine");
            var loc1=GlobalStyle.textFormat6;
            loc1.leading = 6;
            this._tfDes = ObjCreate.createTextField(Language.getString(43210), 25, 245, 285, 40, this, loc1);
            this._tfDes.htmlText = Language.getString(43210);
            this._tfDes.multiline = true;
            this._tfDes.wordWrap = true;
            ObjCreate.createBg(25, 290, 280, 2, this, "SplitLine");
            this._btnFire = ObjCreate.createGButton(Language.getString(43211), 120, 295, 69, 26, this, "ButtonRed");
            this._btnFire.toolTipData = Language.getString(43209);
            this._btnFire.addEventListener(flash.events.MouseEvent.CLICK, this.onClickFire);
            return;
        }

        /* internal  */onClickFire(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.pack.backPackCache.getItemsByJudge(ItemsUtil.isFireworkProp, true);
            if (loc1.length > 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, loc1[0] as ItemData));
            }
            else if (QuickBuyWindow.instance.updateWindow(ECategory._ECategoryProp, EProp._EPropFirework, 1, -1, true)) 
            {
                QuickBuyWindow.instance.updateDefaultAmount(1);
                QuickBuyWindow.instance.show();
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(43201));
            }
            return;
        }

        public updateRecords(arg1: SFireworkEventRecord): void
        {
            var loc1="";
            arg1.eventRecord.reverse();
            var loc2=0;
            while (loc2 < arg1.eventRecord.length) 
            {
                if (loc2 > 0) 
                {
                    loc1 = loc1 + "<br>";
                }
                loc1 = loc1 + this.getRecordDes(loc2 + 1, arg1.eventRecord[loc2] as SFireworkEvent);
                ++loc2;
            }
            this._recordsTextArea.htmlText = "<textFormat leading=\'6\'><font color = \'#B1efff\'>" + loc1 + "</font></font>";
            this._recordsTextArea.verticalScrollPosition = this._recordsTextArea.maxVerticalScrollPosition;
            return;
        }

        /* internal  */getRecordDes(arg1: int, arg2: SFireworkEvent): string
        {
            var loc1=arg1 + ". ";
            var loc2="";
            var loc3=arg2.type;
            switch (loc3) 
            {
                case EFireworkEventType._EFireworkEventTypeOne:
                {
                    loc2 = Language.getStringByParam(43204, this.getPlayerText(arg2.player), arg2.bright.toString());
                    break;
                }
                case EFireworkEventType._EFireworkEventTypeTwo:
                {
                    loc2 = Language.getStringByParam(43205, this.getPlayerText(arg2.player), arg2.bright.toString());
                    break;
                }
                case EFireworkEventType._EFireworkEventTypeThree:
                {
                    loc2 = Language.getStringByParam(43206, this.getPlayerText(arg2.player), arg2.bright.toString());
                    break;
                }
                case EFireworkEventType._EFireworkEventTypeFour:
                {
                    loc2 = Language.getStringByParam(43207, this.getPlayerText(arg2.player), this.getItemText(arg2.code), arg2.bright.toString());
                    break;
                }
                case EFireworkEventType._EFireworkEventTypeFive:
                {
                    loc2 = Language.getStringByParam(43208, this.getPlayerText(arg2.player), arg2.code.toString());
                    break;
                }
            }
            return loc1 + loc2;
        }

        /* internal  */getPlayerText(arg1: SPublicMiniPlayer): string
        {
            return "<font color=\'" + ColorConfig.instance.getCampColor(arg1.camp).color + "\'>" + arg1.name + "</font>";
        }

        /* internal  */getItemText(arg1: int): string
        {
            var loc3=null;
            var loc1=new ItemData(arg1);
            var loc2="#FFFFFF";
            if (loc1 && loc1.color) 
            {
                if (loc3 = ColorConfig.instance.getItemColor(loc1.color)) 
                {
                    loc2 = loc3.color;
                }
            }
            return "<font color=\'" + loc2 + "\'> " + loc1.name + " </font>";
        }

        /* internal */ /* var */_tfDes: Object /* flash.text.TextField */;

        /* internal */ /* var */_btnFire: GButton;

        /* internal */ /* var */_recordsTextArea: GTextArea;
    }
